const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
const _= db.command;
// 云函数入口函数
 exports.main = async (event, context) => {
  var table = event.table;
  var docid = event.docid;
  var cla = event.classname;
  var shux = event.shux;
  if(shux=="classes"){
    return await db.collection(table).doc(docid).update({
      data:{
        classes: _.push([cla])
      }
    })
  }
  if(shux=="removeclass"){
    return await db.collection(table).doc(docid).update({
      data:{
        classes: cla
      }
    })
  }
  if(shux=="checkstudent"){
    return await db.collection(table).doc(docid).update({
      data:{
        yqdname: _.push([cla])
      }
    })
  }
  if(shux=="students"){
    return await db.collection(table).doc(docid).update({
      data:{
        students: _.push([cla])
      }
    })
  }
  if(shux=="name"){
    return await db.collection(table).doc(docid).update({
      data:{
        name:cla
      }
    })
  }
  if(shux=="cheak_teacher"){
    return await db.collection(table).doc(docid).update({
      data:cla
    })
  }
  
}